<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-accelerometer-test2.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     MSAC,                sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-accelerometer-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * mindsensors-accelerometer.h provides an API for the Mindsensors Acceleration Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: More comments&lt;br&gt;</span>
<span class="comment"> *        Make use of the new range defines</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 28 November 2009</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="mindsensors-accelerometer_8h.html" title="Mindsensors ACCEL-nx driver.">drivers/mindsensors-accelerometer.h</a>&quot;</span>

task main () {
  <span class="keywordtype">int</span> _x_tilt = 0;
  <span class="keywordtype">int</span> _y_tilt = 0;
  <span class="keywordtype">int</span> _z_tilt = 0;

  <span class="keywordtype">int</span> tone1;
  <span class="keywordtype">int</span> tone2;
  <span class="keywordtype">int</span> waitTime;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Mindsensors&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;ACCEL-Nx&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 2&quot;</span>);
  wait1Msec(2000);

  <span class="comment">// There are four ranges the ACCL-Nx can measure in</span>
  <span class="comment">// up to 2.5G - MSAC_RANGE_2_5</span>
  <span class="comment">// up to 3.3G - MSAC_RANGE_3_3</span>
  <span class="comment">// up to 6.7G - MSAC_RANGE_6_7</span>
  <span class="comment">// up to 10G  - MSAC_RANGE_10</span>
  <a name="a0"></a><a class="code" href="group__accelnx.html#gacc507ac1b55ac04d6bd5af0a3a78ce0b">MSACsetRange</a>(MSAC, <a name="a1"></a><a class="code" href="group__accelnx.html#gafd2ae083e565b1bcfb31cf85568b273a">MSAC_RANGE_10</a>);

  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// Read the tilt data from the sensor</span>
    <span class="keywordflow">if</span> (!<a name="a2"></a><a class="code" href="group__accelnx.html#ga7b42d4f877b62c7d1b44cd75eb56f160">MSACreadTilt</a>(MSAC, _x_tilt, _y_tilt, _z_tilt)) {
      nxtDisplayTextLine(4, <span class="stringliteral">&quot;ERROR!!&quot;</span>);
      wait1Msec(2000);
      StopAllTasks();
    }

    <span class="comment">// Tilt values seem to go from about -20 to +20.</span>
    <span class="comment">// Adding 20 to them makes them go from 0 to 40.</span>

    <span class="comment">// Make sure the tones are at least 0Hz</span>
    tone1 = <a name="a3"></a><a class="code" href="group__common.html#ga59934691af1d56f6e8f6d46c781bbcb5">max2</a>(0, (_x_tilt + 20) * 20);
    tone2 = <a class="code" href="group__common.html#ga59934691af1d56f6e8f6d46c781bbcb5">max2</a>(0, (_z_tilt + 20) * 25);

    <span class="comment">// Make sure the wait time is at least 10ms</span>
    waitTime = <a class="code" href="group__common.html#ga59934691af1d56f6e8f6d46c781bbcb5">max2</a>(10, (_y_tilt + 20));

    PlayImmediateTone(tone1, 5);
    wait1Msec(waitTime);
    PlayImmediateTone(tone2, 1);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-accelerometer-test2.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
